package com.wquick.base.compose.helper

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density

@Composable
fun ScreenAdapter(
    designWidthDp: Float = 375f,
    content: @Composable () -> Unit
) {

    val fontScale = LocalDensity.current.fontScale
    val displayMetrics = LocalContext.current.resources.displayMetrics
    val widthPixels = displayMetrics.widthPixels
    CompositionLocalProvider(
        LocalDensity provides Density(
            density = widthPixels / designWidthDp,
            fontScale = fontScale
        )
    ) {
        Box {
            content()
        }
    }
}